package org.jsola.hr.helper;

import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendOvertimeRuleAddDTO;
import org.jsola.hr.dto.AttendOvertimeRuleUpdateDTO;
import org.jsola.hr.entity.AttendOvertimeRuleDO;
import org.jsola.hr.query.AttendOvertimeRuleQuery;
import org.jsola.hr.service.IAttendOvertimeRuleService;
import org.jsola.hr.vo.AttendOvertimeRuleVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendOvertimeRuleTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendOvertimeRuleService attendOvertimeRuleService;

    /**
     * 生成add测试数据
     * @return AttendOvertimeRuleAddDTO
     */
    public AttendOvertimeRuleAddDTO getAttendOvertimeRuleAddDTO(){
        AttendOvertimeRuleAddDTO attendOvertimeRuleAddDTO = new AttendOvertimeRuleAddDTO();
        attendOvertimeRuleAddDTO.setAttendPlanId(getRandomValue("varchar",32));
        attendOvertimeRuleAddDTO.setOvertimeType(SafeKit.getInteger(getRandomValue("int",0)));
        attendOvertimeRuleAddDTO.setWorkDayRuleJson(getRandomValue("varchar",255));
        attendOvertimeRuleAddDTO.setNonWorkDayRuleJson(getRandomValue("varchar",255));
        return attendOvertimeRuleAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendOvertimeRuleUpdateDTO
     */
    public AttendOvertimeRuleUpdateDTO getAttendOvertimeRuleUpdateDTO(AttendOvertimeRuleVO attendOvertimeRuleVO){
        return attendOvertimeRuleService.selectDOById(attendOvertimeRuleVO.getId(), SITE_ID).to(AttendOvertimeRuleUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendOvertimeRuleQuery
     */
    public AttendOvertimeRuleQuery getAttendOvertimeRuleQuery() {
        AttendOvertimeRuleQuery attendOvertimeRuleQuery = new AttendOvertimeRuleQuery();
        List<AttendOvertimeRuleDO> attendOvertimeRuleDOList = attendOvertimeRuleService.list(new AttendOvertimeRuleDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendOvertimeRuleDOList)) {
            AttendOvertimeRuleDO attendOvertimeRuleDO = attendOvertimeRuleDOList.get(0);
            attendOvertimeRuleQuery = attendOvertimeRuleDO.to(AttendOvertimeRuleQuery.class);
        }
        return attendOvertimeRuleQuery;
    }

    /**
     * 保存示例
     * @return AttendOvertimeRuleVO
     */
    public AttendOvertimeRuleVO saveAttendOvertimeRuleExample(){
        AttendOvertimeRuleAddDTO addDTO = this.getAttendOvertimeRuleAddDTO();
        AttendOvertimeRuleVO attendOvertimeRuleVO = attendOvertimeRuleService.save(addDTO,buildTokenUser());
        return attendOvertimeRuleVO;
    }


}

